var Swith={
    swithType:{off:0,no:1},
    status:false,
    name:"",
    doExe:function(toStatus){
        app.launchApp("米家");
        if(toStatus==0){
            toStatus="已关闭";
        }else{
            toStatus="已开启";
        }
        id("img_fl").className("android.widget.FrameLayout").selected(true).waitFor();
        console.log("操作对象："+this.name )
        var o = text(this.name).findOne().parent();
        o.click();
        id("status_icon").waitFor()
        var button=id("status_icon").findOne().parent();
        this.status = id("tv_status").findOne().text();
        console.log("设备现在状态："+this.status,"目标状态："+ toStatus);
        if(this.status!=toStatus){
            this.status==toStatus;
            console.log(button)
            button.click();
            
            //检查状态重新操作
            // for (let index = 0; index < 3; index++) {
            //     sleep(500);
            //     id("status_icon").waitFor();
            //     var buttonR=id("status_icon").findOne().parent();
            //     var afterStatus=id("tv_status").findOne().text();
            //     if(afterStatus!=toStatus){
            //         console.log("操作失败，重新操作");
            //         buttonR.click();
            //     }
            // }
            
            console.log("操作成功");
        }else{
            this.status==toStatus;
            console.log("状态相同,未操作");
        }
        back();
    },
    init:function(name){
        this.name=name;
        app.launchApp("米家");
        id("img_fl").className("android.widget.FrameLayout").selected(true).waitFor();
        var o = text(name).findOne().parent();
        o.click();
        id("status_icon").waitFor();
        this.status= id("tv_status").findOne().text();
        back();
    },
    isOK:function(){
        var vsion =device.sdkInt;
        //安卓7.0 sdkInt=24
        var vsionIs7=vsion>=24;
        //不是7.0
        if(!vsionIs7){
            toastLog("vsion:"+vsion);
            runtime.loadJar("/storage/emulated/0/脚本/jar/RootTools.jar")
            importClass(com.stericson.RootTools.RootTools);
            toastLog("是否root:"+isRoot());
            if(!isRoot()){
                toastLog("对不起,硬件系统版本不支持");
                return false;
            }
        }
        toastLog("恭喜你的手机可以使用!");  
        return true;  
    },
    isRoot:function(){
        return RootTools.isRootAvailable();
    }    
};

module.exports = Swith;
